#include "StdAfx.h"
#include "I2C_PCF8574.h"

I2C_PCF8574::I2C_PCF8574(ComPorts* com, unsigned char Adresse)
{
	C1 = com;
	Adress = Adresse;
}

I2C_PCF8574::~I2C_PCF8574(void)
{
}


int I2C_PCF8574::set_port(unsigned char PortState)
{
	C1 -> I2C_start();
	C1 -> I2C_tx_byte(Adress);
	// Check for acknowledge from I2C device
	if (!C1 -> I2C_read_ack())	return 1000;
	C1 -> I2C_tx_byte(PortState);
	if (!C1 -> I2C_read_ack())	return 2000;
	C1 -> I2C_send_nack();
	C1 -> I2C_stop();
	return 0;
}